package com.jinlejia.bbs.ui.fun;

import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.view.View;

import com.jinlejia.bbs.R;
import com.jinlejia.bbs.databinding.BbsActivityAskBinding;
import com.jinlejia.bbs.help.CommonEvent;
import com.jinlejia.bbs.logic.AskLogic;
import com.jinlejia.bbs.widget.BBSToast;

public class BBSAskActivity extends AppCompatActivity implements AskLogic.LogicCallBack {
    private BbsActivityAskBinding binding;
    private AskLogic logic;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.bbs_activity_ask);
        binding.setEvent(this);
        binding.setCommonEvent(CommonEvent.obtain());
        logic = new AskLogic(this,this);
    }

    public void back(View view){
        this.finish();
    }

    public void askQuestion(View view){
        Editable text = binding.editText.getText();
        if (TextUtils.isEmpty(text)){
            BBSToast.showToast(this,"请输入提问内容",1500);
            return;
        }
        if (text.length()<8){
            BBSToast.showToast(this,"请输入8个字符以上",1500);
            return;
        }
        logic.execute(text.toString());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        binding.unbind();
    }

    @Override
    public void onResult(boolean flag) {
        if (flag){
            setResult(RESULT_OK);
            this.finish();
        }
    }
}
